package com.chess.db.bean;

import org.apache.commons.lang3.ArrayUtils;
import java.util.Map;
import com.chess.db.cache.UserCache;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.build.data.base.BasePojo;
import com.sojoys.artifact.tools.ToolCopy;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
/**
 * user
 */
public class User extends BasePojo<User>{
	/**
	 * 数据库表名称
	 */
	public static final String TABLE_NAME = "user";
	/**
	 * 完整类名称
	 */
	public static final String CLASS_NAME = "com.chess.db.bean.User"; 
	/**
	 * 数据库源字段名字
	 */
	public static final String[] SOURCE_COLUMN_NAMES = new String[]{"id","code","channel","name","deviceId","deviceName","deviceToken","osName","osVersion","sdkName","sdkVersion","mcc","lastLoginDate","createDate","modifiedDate",};
	/**
	 * 拼音字段名字
	 */
	public static final String[] PINGYING_COLUMN_NAMES = new String[]{"id","code","channel","name","deviceId","deviceName","deviceToken","osName","osVersion","sdkName","sdkVersion","mcc","lastLoginDate","createDate","modifiedDate",};
	/**
	 * HashCode字段名字
	 */
	public static final Integer[] HASHCODE_COLUMN_NAMES = new Integer[]{3355,3059181,738950403,3373707,1109191185,780988929,-1553190589,-1008506225,1812004436,1947860453,-1962630338,107917,780831937,1368729290,-626009577,};
	/**
	 * 字段基本类型
	 */
	public static final String[] COLUMN_BASICTYPES = new String[]{"String","String","String","String","String","String","String","String","String","String","String","String","java.util.Date","java.util.Date","java.util.Date",};
	/**
	 * 字段引用类型
	 */
	public static final Class<?>[] COLUMN_CLASSTYPES = new Class[]{String.class,String.class,String.class,String.class,String.class,String.class,String.class,String.class,String.class,String.class,String.class,String.class,java.util.Date.class,java.util.Date.class,java.util.Date.class,};
	/**
	 * 字段个数
	 */
	public static final int COLUMN_COUNT= 15;
	
	/**
	 * 关联表源名称
	 */ 
	public static final String[] FK_SOURCE_TABLE_NAMES = new String[]{};
	
	/**
	 * 关联表拼音名称
	 */
	public static final String[] FK_PINGYING_TABLE_NAMES = new String[]{};
	
	/**
	 * 关联表HashCode名称
	 */ 
	public static final Integer[] FK_HASHCODE_TABLE_NAMES = new Integer[]{};
	
	/**
	 * 关联表所关联字段源名
	 */ 
	public static final String[] FK_SOURCE_COLUMN_NAMES = new String[]{};
	
	/**
	 * 关联表所关联字段拼音名
	 */ 
	public static final String[] FK_PINGYING_COLUMN_NAMES = new String[]{};
	
	/**
	 * 关联表所关联字段hashcode名
	 */ 
	public static final Integer[] FK_HASHCODE_COLUMN_NAMES = new Integer[]{};
	
	/**
	 * 索引名称
	 */
	public static final String[] TABLE_INDEX_NAMES = new String[]{"id","codechannel",};
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[2];
	
	/** id */
	private String id;
	
	/** 唯一码(渠道Uid) */
	private String code;
	
	/** 渠道标示 */
	private String channel;
	
	/** 昵称 */
	private String name;
	
	/** 设备唯一编号 */
	private String deviceId;
	
	/** 设备名称 */
	private String deviceName;
	
	/** 设备token */
	private String deviceToken;
	
	/** 系统名称 */
	private String osName;
	
	/** 系统版本 */
	private String osVersion;
	
	/** sdk名称 */
	private String sdkName;
	
	/** sdk版本号 */
	private String sdkVersion;
	
	/** 移动设备国家码 */
	private String mcc;
	
	/** 最后登录时间 */
	private java.util.Date lastLoginDate;
	
	/** createDate */
	private java.util.Date createDate;
	
	/** modifiedDate */
	private java.util.Date modifiedDate;
	
	
	public static User builder() {
		User user = new User();
		return user;
	}
	
	public User() {
		super();
	}
	
	public User(String id, String code, String channel, String name, String deviceId, String deviceName, String deviceToken, String osName, String osVersion, String sdkName, String sdkVersion, String mcc, java.util.Date lastLoginDate, java.util.Date createDate, java.util.Date modifiedDate) {
		super();
		this.id = id;
		this.code = code;
		this.channel = channel;
		this.name = name;
		this.deviceId = deviceId;
		this.deviceName = deviceName;
		this.deviceToken = deviceToken;
		this.osName = osName;
		this.osVersion = osVersion;
		this.sdkName = sdkName;
		this.sdkVersion = sdkVersion;
		this.mcc = mcc;
		this.lastLoginDate = lastLoginDate;
		this.createDate = createDate;
		this.modifiedDate = modifiedDate;
	}
	
	/** id */
	public String getId() {
		return id;
	}
	
	/** id */
	public void setId(String id) {
		this.id = id;
		addUpdateColumn(SOURCE_COLUMN_NAMES[0],id);
	}
	
	/** 唯一码(渠道Uid) */
	public String getCode() {
		return code;
	}
	
	/** 唯一码(渠道Uid) */
	public void setCode(String code) {
		this.code = code;
		addUpdateColumn(SOURCE_COLUMN_NAMES[1],code);
	}
	
	/** 渠道标示 */
	public String getChannel() {
		return channel;
	}
	
	/** 渠道标示 */
	public void setChannel(String channel) {
		this.channel = channel;
		addUpdateColumn(SOURCE_COLUMN_NAMES[2],channel);
	}
	
	/** 昵称 */
	public String getName() {
		return name;
	}
	
	/** 昵称 */
	public void setName(String name) {
		this.name = name;
		addUpdateColumn(SOURCE_COLUMN_NAMES[3],name);
	}
	
	/** 设备唯一编号 */
	public String getDeviceId() {
		return deviceId;
	}
	
	/** 设备唯一编号 */
	public void setDeviceId(String deviceId) {
		this.deviceId = deviceId;
		addUpdateColumn(SOURCE_COLUMN_NAMES[4],deviceId);
	}
	
	/** 设备名称 */
	public String getDeviceName() {
		return deviceName;
	}
	
	/** 设备名称 */
	public void setDeviceName(String deviceName) {
		this.deviceName = deviceName;
		addUpdateColumn(SOURCE_COLUMN_NAMES[5],deviceName);
	}
	
	/** 设备token */
	public String getDeviceToken() {
		return deviceToken;
	}
	
	/** 设备token */
	public void setDeviceToken(String deviceToken) {
		this.deviceToken = deviceToken;
		addUpdateColumn(SOURCE_COLUMN_NAMES[6],deviceToken);
	}
	
	/** 系统名称 */
	public String getOsName() {
		return osName;
	}
	
	/** 系统名称 */
	public void setOsName(String osName) {
		this.osName = osName;
		addUpdateColumn(SOURCE_COLUMN_NAMES[7],osName);
	}
	
	/** 系统版本 */
	public String getOsVersion() {
		return osVersion;
	}
	
	/** 系统版本 */
	public void setOsVersion(String osVersion) {
		this.osVersion = osVersion;
		addUpdateColumn(SOURCE_COLUMN_NAMES[8],osVersion);
	}
	
	/** sdk名称 */
	public String getSdkName() {
		return sdkName;
	}
	
	/** sdk名称 */
	public void setSdkName(String sdkName) {
		this.sdkName = sdkName;
		addUpdateColumn(SOURCE_COLUMN_NAMES[9],sdkName);
	}
	
	/** sdk版本号 */
	public String getSdkVersion() {
		return sdkVersion;
	}
	
	/** sdk版本号 */
	public void setSdkVersion(String sdkVersion) {
		this.sdkVersion = sdkVersion;
		addUpdateColumn(SOURCE_COLUMN_NAMES[10],sdkVersion);
	}
	
	/** 移动设备国家码 */
	public String getMcc() {
		return mcc;
	}
	
	/** 移动设备国家码 */
	public void setMcc(String mcc) {
		this.mcc = mcc;
		addUpdateColumn(SOURCE_COLUMN_NAMES[11],mcc);
	}
	
	/** 最后登录时间 */
	public java.util.Date getLastLoginDate() {
		return lastLoginDate;
	}
	
	/** 最后登录时间 */
	public void setLastLoginDate(java.util.Date lastLoginDate) {
		this.lastLoginDate = lastLoginDate;
		addUpdateColumn(SOURCE_COLUMN_NAMES[12],lastLoginDate);
	}
	
	/** createDate */
	public java.util.Date getCreateDate() {
		return createDate;
	}
	
	/** createDate */
	public void setCreateDate(java.util.Date createDate) {
		this.createDate = createDate;
		addUpdateColumn(SOURCE_COLUMN_NAMES[13],createDate);
	}
	
	/** modifiedDate */
	public java.util.Date getModifiedDate() {
		return modifiedDate;
	}
	
	/** modifiedDate */
	public void setModifiedDate(java.util.Date modifiedDate) {
		this.modifiedDate = modifiedDate;
		addUpdateColumn(SOURCE_COLUMN_NAMES[14],modifiedDate);
	}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class<?>[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.code;
        values[2] = this.channel;
        values[3] = this.name;
        values[4] = this.deviceId;
        values[5] = this.deviceName;
        values[6] = this.deviceToken;
        values[7] = this.osName;
        values[8] = this.osVersion;
        values[9] = this.sdkName;
        values[10] = this.sdkVersion;
        values[11] = this.mcc;
        values[12] = this.lastLoginDate;
        values[13] = this.createDate;
        values[14] = this.modifiedDate;
        return values;
	}
	
	public User deepCopy(){
		User user = null;
		try {
			user = (User) super.clone();
			user.setUpdateColumn(ToolCopy.copyObject(this.updateColumn));
		    user.setLastLoginDate(ToolCopy.copyObject(this.lastLoginDate));
		    user.setCreateDate(ToolCopy.copyObject(this.createDate));
		    user.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    user.indexValues = ArrayUtils.clone(indexValues);
			return user;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return user;
	}
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map,boolean encode){
        map.put(keys[0], this.id);
        map.put(keys[1], this.code);
        map.put(keys[2], this.channel);
        map.put(keys[3], this.name);
        map.put(keys[4], this.deviceId);
        map.put(keys[5], this.deviceName);
        map.put(keys[6], this.deviceToken);
        map.put(keys[7], this.osName);
        map.put(keys[8], this.osVersion);
        map.put(keys[9], this.sdkName);
        map.put(keys[10], this.sdkVersion);
        map.put(keys[11], this.mcc);
        map.put(keys[12], this.lastLoginDate);
        map.put(keys[13], this.createDate);
        map.put(keys[14], this.modifiedDate);
        return map;
    }
    
    protected User createForMap(Object[] keys,Map<?, ?> map,boolean decode){
	    this.id = ToolMap.getString(keys[0], map);
	    this.code = ToolMap.getString(keys[1], map);
	    this.channel = ToolMap.getString(keys[2], map);
	    this.name = ToolMap.getString(keys[3], map);
	    this.deviceId = ToolMap.getString(keys[4], map);
	    this.deviceName = ToolMap.getString(keys[5], map);
	    this.deviceToken = ToolMap.getString(keys[6], map);
	    this.osName = ToolMap.getString(keys[7], map);
	    this.osVersion = ToolMap.getString(keys[8], map);
	    this.sdkName = ToolMap.getString(keys[9], map);
	    this.sdkVersion = ToolMap.getString(keys[10], map);
	    this.mcc = ToolMap.getString(keys[11], map);
	    this.lastLoginDate = ToolMap.getDate(keys[12], map);
	    this.createDate = ToolMap.getDate(keys[13], map);
	    this.modifiedDate = ToolMap.getDate(keys[14], map);
        return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeString(this.id);
	    byteBuf.writeString(this.code);
	    byteBuf.writeString(this.channel);
	    byteBuf.writeString(this.name);
	    byteBuf.writeString(this.deviceId);
	    byteBuf.writeString(this.deviceName);
	    byteBuf.writeString(this.deviceToken);
	    byteBuf.writeString(this.osName);
	    byteBuf.writeString(this.osVersion);
	    byteBuf.writeString(this.sdkName);
	    byteBuf.writeString(this.sdkVersion);
	    byteBuf.writeString(this.mcc);
	    byteBuf.writeDate(this.lastLoginDate);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected User readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readString(null);
	    this.code = byteBuf.readString(null);
	    this.channel = byteBuf.readString(null);
	    this.name = byteBuf.readString(null);
	    this.deviceId = byteBuf.readString(null);
	    this.deviceName = byteBuf.readString(null);
	    this.deviceToken = byteBuf.readString(null);
	    this.osName = byteBuf.readString(null);
	    this.osVersion = byteBuf.readString(null);
	    this.sdkName = byteBuf.readString(null);
	    this.sdkVersion = byteBuf.readString(null);
	    this.mcc = byteBuf.readString(null);
	    this.lastLoginDate = byteBuf.readDate(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected Map<?,?> exportFKTableMap(Object[] keys,Map<Object, Object> map,DataModelKeyEnum e,boolean encode){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,Map<Object, Object> map,DataModelKeyEnum e,boolean decode){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public User insert(){
    	return UserCache.getInstance().insert(this);
    }
    /** 延迟更新数据库 */
    public User update(){
    	return UserCache.getInstance().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return UserCache.getInstance().delete(this);
    }
    /** 即时插入数据库 */
    public User insertAndFlush(){
    	return UserCache.getInstance().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public User updateAndFlush(){
    	return UserCache.getInstance().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return UserCache.getInstance().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public User syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getCode(),"_",getChannel()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	public Object getPrimaryKey(){
		return getId();
	}
	
	public void setPrimaryKey(Object key){
		setId((String)key);
	}
	
//自定义内容起始位置
//自定义内容结束位置
}